/**
 * projectName: 47movie-project
 * fileName: JwtUtil.java
 * packageName: com.woniu.utils.salt
 * date: 2021-01-05 6:31 下午
 * copyright(c) 2017-2020 xxx公司
 */
package com.damie.common.jwtuilts;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.security.Keys;

import java.security.Key;
import java.util.Date;
import java.util.Map;

/**
 * @version: V1.0
 * @author: light
 * @className: JwtUtil
 * @packageName: com.woniu.utils.salt
 * @description:
 * @data: 2021-01-05 6:31 下午
 **/
public class JwtUtil {
    //自定义的秘钥
    static String sect = "laisdjfoiwqjflksaasfdasdfadsfwfrasdfsadffcasijfasadfasfdlkfjlasjflksajfd";
    //生成token
    public static String createToken(Map<String, Object> body, Integer mil) {
        Key key = Keys.hmacShaKeyFor(sect.getBytes());
        return Jwts.builder()
                .setClaims(body)
                .setExpiration(new Date(System.currentTimeMillis() + mil * 60 * 1000))
                .signWith(key)
                .compact();
    }
    //解析token
    public static Claims parseToken(String token) {
        Key key = Keys.hmacShaKeyFor(sect.getBytes());
        return Jwts.parserBuilder().setSigningKey(key).build().parseClaimsJws(token).getBody();
    }

}
